package com.yehuishou.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yehuishou.dao.AssessmentValueDao;
import com.yehuishou.dao.BackAssessmentDao;
import com.yehuishou.dao.BackItemDao;
import com.yehuishou.dao.FileDao;
import com.yehuishou.pojo.AssessmentValue;
import com.yehuishou.pojo.BackAssessment;
import com.yehuishou.pojo.BackItem;
import com.yehuishou.service.AssessmentValueService;

/**
	 * 
	 * @author xiaosa
	 * @className AssessmentValueServiceImpl.java
	 * @descripe 
	 * @data 2018年6月6日
	 */
    @Service
	public class AssessmentValueServiceImpl implements AssessmentValueService{
		
		@Resource
		private AssessmentValueDao assessmentValueDao;
		
		
		@Resource
		private BackItemDao backItemDao;
		
		
		@Resource
		private BackAssessmentDao backAssessmentDao;
		
		
		@Resource
	    private FileDao fileDao;
		
		
		public void insertAssessmentValue(AssessmentValue value) {
			
			assessmentValueDao.insertAssessValue(value);
			
		}

         //根据back_id 和assess_id 查集合
		@Override
		public List<AssessmentValue> getAssessmentValue(AssessmentValue value) {
		
			List<AssessmentValue> valuelist =new ArrayList<>();
			valuelist=assessmentValueDao.getAssessmentValueByid(value);
			return valuelist;
		}


		@Override
		public void deleteAssessById(Integer id) {
			assessmentValueDao.deleteAssessById(id);
		}


		@Override
		public void editAssess(AssessmentValue value) {
			assessmentValueDao.editAssess(value);
		}

		@Override
		public Map<String, Object> getAssessmentValueByids(String[] vals) {
			
			Map<String, Object> map = new HashMap<>();
			List<AssessmentValue> asList = new ArrayList<>();
			Double p =0.0;
			for(int i=1;i<vals.length;i++) {
			AssessmentValue as =assessmentValueDao.getAssessmentValueByvalid(Integer.parseInt(vals[i]));
			asList.add(as);
			  p+=as.getAssess_price();
			}
			Integer back_id= asList.get(0).getBack_id();
			
		BackItem ba =backItemDao.getBackItemById(back_id);
		String img_url =ba.getImg_url();
		String img="";
		if(img_url.split(";").length>1) {
			 img =fileDao.getOneImage(Integer.parseInt(img_url.split(";")[1])).getFilePath();
			
		}
		    Double d =ba.getBackprice()-p;
		    ba.setBackprice(d);
			map.put("asList", asList);
			ba.setImg_url(img);
			map.put("ba",ba);
			return map;
		}
		
		

}
